$(document).ready(function () {
    $('#adminname').keyup(function () {
        checkadminname();
    });
    $('#adminpassword').keyup(function () {
        checkadminpassword();
    });
    $('#sub').click(function () {
        return checksub();
    });
});

function checkadminname() {
    var ret =false;
    var adminname = $('#adminname').val();
    if (adminname==''){
        $('#namespan').text('请填写用户名').css('color', 'red');
    }else {
        ret=true;
        $('#namespan').text('请填写用户名').css('color', '#ffffff');
    }
    return ret;
}
function  checkadminpassword() {
    var ret =false;
    var adminpassword = $('#adminpassword').val();
    if (adminpassword==''){
        $('#passwordspan').text('请填写密码').css('color', 'red');
    }else {
        ret=true;
        $('#passwordspan').text('请输入密码').css('color', '#ffffff');
    }
    return ret;
}
function adminlogin() {
    var adminname = $('#adminname').val();
    var adminpassword = $('#adminpassword').val();
    var ret = false;
    $.ajax({
        url: "/yuhan/index.php/home/admin/adminLogin",
        type: 'post',
        //cache: false,
        async: false,
        dataType: 'json',
        data: {adminname: adminname,adminpassword:adminpassword},
        success: function (data) {
            console.log(data);
            if (data.info == "1") {
                ret = true;
                $('#from').attr('action',"/yuhan/index.php/home/Admin/toMain");
            }else {
                $('#passwordspan').text(data.info).css('color','red');
            }

        },
        error:function (mes) {
            console.log(mes);
        }
    });
    return ret;
}
function checksub() {
    if (!checkadminname()) {
        return false;
    }
    if (!checkadminpassword()) {
        return false;
    }
    if (!adminlogin()) {
        return false;
    }
}
